﻿using MediatR;
using ProductionLine.API.Application.Command.Dispatch;
using ProductionLine.Domain.Team;
using ProductionLine.ErrorCode;
using ProductionLine.Extensions;
using ProductionLine.Infrastructure.Interface;

namespace ProductionLine.API.Application.Handler.Dispatch
{
    public class GetTeamHandler : IRequestHandler<GetTeamCommand, APIResult<List<TeamModel>>>
    {
        IBaseRepository<TeamModel> _repository;
       

        public GetTeamHandler(IBaseRepository<TeamModel> repository)
        {
            _repository = repository;
           
        }

        public Task<APIResult<List<TeamModel>>> Handle(GetTeamCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<TeamModel>> res=new APIResult<List<TeamModel>>();
            var team = _repository.GetAll().Where(x => !x.IsDel).ToList();
            res.Code = APIEnum.Success;
            res.Data = team;
            res.Msg = "查询班组信息成功";
            return Task.FromResult(res);
        }
    }
}
